import java.util.ArrayList;
import java.util.List;

/**
 * This class holds a search item that has a type and various associated properties. Should be extended for specific items. (ie music)
 */
public abstract class SearchItem
{
	private Type classType;
	private List<SearchProperty> searchProperties;
	
	public SearchItem(Type classType, SearchProperty.Type... types)
	{
		this.classType = classType;
		searchProperties = new ArrayList<SearchProperty>(types.length);
		for(SearchProperty.Type type : types)
			searchProperties.add(new SearchProperty(type));
	}
	
	public static enum Type
	{
		MOVIE,
		MUSIC,
		PHOTO,
		VIDEO;
	}
	
	public static String getSearchClass(Type type)
	{
		switch (type)
		{
			case MOVIE: return "object.item.videoItem.movie";
			case MUSIC: return "object.item.audioItem.musicTrack";
			case PHOTO: return "object.item.imageItem.photo";
			case VIDEO: return "object.item.videoItem";
			default: throw new IllegalArgumentException("Invalid Search Class");
		}
		
	}
	
	public static String getTypeString(Type type)
	{
		switch (type)
		{
			case MOVIE: return "Movie";
			case MUSIC: return "Music";
			case PHOTO: return "Photo";
			case VIDEO: return "Video";
			default: throw new IllegalArgumentException("Invalid Search Class");
		}
	}
	
	protected boolean isValidProperty(SearchProperty.Type type)
	{
		for(SearchProperty p : searchProperties)
			if(p.getType() == type)
				return true;
		
		return false;
	}
	
	public Type getClassType()
	{
		return classType;
	}

	public List<SearchProperty> getSearchProperties()
	{
		List<SearchProperty> set = new ArrayList<SearchProperty>();
		for(SearchProperty p : searchProperties)
			if(p.getValue() != null)
				set.add(p);
		
		return set;
	}
}
